#------------------------------------------------------------------------------
# Project:     Multi-Programmer Game Demo
# Name:        Ball.py
# Purpose:     Bouncing Ball Object
# 
# Authors:     Chris Spooner, Chris La-Roo
# Main Author: Chris Spooner
#
# Created:     11/30/2012
# Copyright:   (c) Chris Spooner 2012
# Licence:     New BSD
#------------------------------------------------------------------------------
import pygame, math, sys, random


class Ball():
    def __init__(self, images, speed, screenSize, waitMax = 1000):
        self.surfaces = []
        for image in images:
            surf = pygame.image.load(image)
            surf = pygame.transform.scale(surf, (16,16))
            self.surfaces += [surf]
        self.frame = 0
        self.waitCount = 0
        self.waitMax = waitMax
        self.maxFrame = len(self.surfaces)-1
        self.surface = self.surfaces[self.frame]
        self.rect = self.surface.get_rect()
        self.radius = self.rect.width/2
        self.speed = speed
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.living = True
        self.go = True
        self.pt = [0,0]
        if pygame.mixer:
            self.bounceSound = pygame.mixer.Sound("bounce.wav")
        
    def  __str__(self):
        return "I'm a ball " + str(self.rect.center) + str(self.speed) + str(self.living)
     
    def move(self):
        self.rect = self.rect.move(self.speed)
        self.pt = self.rect.center
                
    def place(self, pt):
        self.rect.center = pt
        # -1
        
    def collideFloor(self):
        if (self.rect.top < 0 
            or self.rect.bottom >self.screenHeight):
            self.speed[1] = self.speed[1]*-1
    
    def collideWall(self):
        if (self.rect.left < 0 
            or self.rect.right > self.screenWidth):
            self.place([400, 300])